Skip to content

Check if any gateways exist before iterating#7960

Closed
jiuka wants to merge 1 commit intoopnsense:masterfrom
jiuka:delete_gateway
Closed

Check if any gateways exist before iterating#7960
jiuka wants to merge 1 commit intoopnsense:masterfrom
jiuka:delete_gateway

Conversation

@jiuka
Copy link
Copy Markdown

@jiuka jiuka commented Oct 10, 2024

Important notices

Before you add a new report, we ask you kindly to acknowledge the following:

Describe the bug

On a fresh OPNsense configuration the key /opnsense/gateways does not exist in the config.xml. If a Gateway is created and then deleted an error is raise.

foreach() argument must be of type array|object, null given

To delete the gateway a gateway group needs to be createt (and can be deleted again). This leafs the following in the config.xml.

  <gateways>
    <gateway_group/>
  </gateways>

To Reproduce

Steps to reproduce the behavior:

  1. Delete the gateways node from config.xml
  2. Create a Gateway
  3. Delete the Gateway
  4. See error

Expected behavior

The gateway should be deleted.

Describe alternatives you considered

Screenshots

Relevant log files

[10-Oct-2024 15:04:52 Etc/UTC] ErrorException: foreach() argument must be of type array|object, null given in /usr/local/opnsense/mvc/app/controllers/OPNsense/Routing/Api/SettingsController.php:208
Stack trace:
#0 /usr/local/opnsense/mvc/app/controllers/OPNsense/Routing/Api/SettingsController.php(208): {closure}(2, 'foreach() argum...', '/usr/local/opns...', 208)
#1 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Dispatcher.php(165): OPNsense\Routing\Api\SettingsController->delGatewayAction('bcad02aa-a52d-4...')
#2 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Router.php(156): OPNsense\Mvc\Dispatcher->dispatch(Object(OPNsense\Mvc\Request), Object(OPNsense\Mvc\Response), Object(OPNsense\Mvc\Session))
#3 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Router.php(139): OPNsense\Mvc\Router->performRequest(Object(OPNsense\Mvc\Dispatcher))
#4 /usr/local/opnsense/www/api.php(36): OPNsense\Mvc\Router->routeRequest('/api/routing/se...', Array)
#5 {main}

Additional context

Environment

Software version used and hardware type if relevant, e.g.:

OPNsense 24.7.6-amd64

@fichtner fichtner self-assigned this Oct 10, 2024
@fichtner
Copy link
Copy Markdown
Member

Hi @jiuka,

Thanks for the details. I currently fail to reproduce this locally no matter what data I try to push there.

I do expect some remaining issues from the gateway MVC conversion (and gateway groups not having followed yet), but I'd like to be careful with breaking this area even though your fix looks reasonable the problem could be worse and masked using this change.

Cheers,
Franco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants